//
//  BaseFormsController.swift
//  fho
//
//  Created by 郭颢源 on 2021/4/26.
//

import UIKit

class BaseFormsController: UIViewController {
    var isEdit = false//判断tableview是否是在编辑状态
    lazy var requestDict : NSMutableDictionary = {
        var dict = NSMutableDictionary()
        return dict
        
    }()
    lazy var uploadDict : NSMutableDictionary = {
        var dict = NSMutableDictionary()
        return dict
    }()
    var haveHeader : Bool = true
    lazy var datas : Array<JSFormHeaderModel> = []
//    lazy var datas:NSMutableArray = {
//        var array = NSMutableArray()
//        //        for i in 1...22{
//        //            array.add(NSNumber(value: i).stringValue)
//        //        }
//        return array
//        
//    }()
    let sectionHeaderHeight:CGFloat = 60
    let sectionFooterHeight:CGFloat = 40
    lazy var tableView:UITableView = {
        var table = UITableView(frame: .zero, style: .plain)
        table.showsVerticalScrollIndicator = false//垂直滚动指示器
        table.showsHorizontalScrollIndicator = false//水平滚动指示器
        //        table.bounces = false//弹簧效果
        //        table.separatorStyle = .none//分割线
        table.estimatedRowHeight = 0//预设行高
        table.estimatedSectionFooterHeight = 0//预设分区头高度
        table.estimatedSectionHeaderHeight = 0
        table.backgroundColor = UIColor.white
        
        if #available(iOS 11.0, *) {
            table.contentInsetAdjustmentBehavior = UIScrollView.ContentInsetAdjustmentBehavior.always
        }
        return table
        
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        // Do any additional setup after loading the view.
        
        self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "UITableViewCell")
        self.tableView.register(JSTextFieldCell.self, forCellReuseIdentifier: "JSTextFieldCell")
        self.tableView.register(JSArrowCell.self, forCellReuseIdentifier: "JSArrowCell")
        self.tableView.register(JSArrowValue1Cell.self, forCellReuseIdentifier: "JSArrowValue1Cell")
        self.tableView.register(JSLabelCell.self, forCellReuseIdentifier: "JSLabelCell")
        self.tableView.register(JSSwitchCell.self, forCellReuseIdentifier: "JSSwitchCell")
        self.tableView.register(JSTextViewCell.self, forCellReuseIdentifier: "JSTextViewCell")
        self.tableView.register(JSRadioBoxCell.self, forCellReuseIdentifier: "JSRadioBoxCell")
        self.tableView.register(JSCheckBoxCell.self, forCellReuseIdentifier: "JSCheckBoxCell")
        self.tableView.register(JSMediaViewCell.self, forCellReuseIdentifier: "JSMediaViewCell")
        self.tableView.register(JSSegmentedControlCell.self, forCellReuseIdentifier: "JSSegmentedControlCell")
        self.tableView.register(JSStepperCell.self, forCellReuseIdentifier: "JSStepperCell")
        
    }
    public func loadDataWithFileName(fileName: String) {

//        self.datas.addObjects(from: JSFormModelTool.getFieldModelsWithFileName(fileName: fileName) as! [Any])
//        self.haveHeader = self.datas.firstObject is JSFormHeaderModel
        self.datas.append(contentsOf: JSFormModelTool.getFieldModelsWithFileName(fileName: fileName) as! Array<JSFormHeaderModel>)
        self.haveHeader = (self.datas.first != nil)
//        haveHeader = (datas.firstObject != nil)
//        let tmp = datas.firstObject
//        haveHeader = (NSStringFromClass(tmp as! JSFormModel).compare("JSFormHeaderModel").rawValue != 0)
        
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
